package sensorlogic;

import gui.SwitcherForm;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: kate
 * Date: 01.06.2009
 * Time: 18:58:11
 * To change this template use File | Settings | File Templates.
 */
public class SwitcherLogic extends Thread {

    private SwitcherForm jframe;
    private boolean isProcessing;
    Container cp;
    JPanel imagePanel;
    int temp;
    int timer;

    public SwitcherLogic(SwitcherForm jframe) {

        this.jframe = jframe;

    }

    public void run() {

        try {
            while (true) {
                if (isProcessing) {
                    String data = jframe.switcher.recv();
                    System.out.println("Recieved data..." + data);
                    if (data.compareTo("OFF") == 0) {
                        System.out.println("Recieved data..." + data);
                        jframe.colorPanel.setBackground(Color.BLACK);
                        jframe.pictureForm.testPanel.setNewImage("kidOff.jpg");
                        jframe.pictureForm.repaint();
                        jframe.switcher.setOff();
                        jframe.repaint();
                    }
                    if (data.compareTo("ON") == 0) {
                        System.out.println("Recieved data..." + data);
                        jframe.colorPanel.setBackground(Color.WHITE);
                        jframe.pictureForm.testPanel.setNewImage("kidOn.jpg");
                        jframe.pictureForm.repaint();
                        jframe.switcher.setOff();
                        jframe.repaint();
                    }

                    // jframe.repaint();
                }
            }
        } catch (Exception ex) {
        }
        ;

    }


    public void startProcessing() {
        isProcessing = true;
    }

    public void stopProcesing() {
        isProcessing = false;
    }
}
